package Test;


import SysUserMapper.SysUserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class SysUserMapperTestTest {

    @Test
    public void count() throws IOException{
        SqlSession sqlSession = null;
        try {
            //1.读取MyBatis框架的核心配置文件
            String resource = "mybatis-config.xml";
            //2.获取对mybatis-config.xml的输入流
            InputStream is = Resources.getResourceAsStream(resource);
            //使用SqlSessionFactoryBuilder读取配置文件并构建
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
            //创建SqlSession实例
            sqlSession = factory.openSession();
            //创建SysUserMapper接口实例，调用其他方法执行相关的SQL语句
            int count = sqlSession.getMapper(SysUserMapper.class).count();

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            sqlSession.close();
        }
    }
}